package ${package}.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import ${package}.pojo.entity.${ClassName}Entity;
import ${package}.pojo.param.${ClassName}Params;
import ${package}.pojo.vo.${ClassName}VO;
import ${package}.service.${ClassName}Service;
import org.wang.generalcode.support.mybaties.Condition;
import org.wang.generalcode.support.mybaties.Query;
import org.wang.generalcode.support.result.PageResult;
import org.wang.generalcode.support.result.Result;
import org.wang.generalcode.support.utils.Func;

/**
 * ${tableComment}前端控制层
 *
 * @author ${author}
 * @since ${date}
 */
@Tag(name = "${tableComment}接口")
@RestController
@RequestMapping("${moduleName}/${functionName}")
@RequiredArgsConstructor
public class ${ClassName}Controller {

    private final ${ClassName}Service ${ClassName?lower_case}Service;

    @Operation(summary = "${tableComment}分页列表")
    @GetMapping("/page")
    public PageResult<${ClassName}VO> get${ClassName}Page(${ClassName}Params queryParams, Query query) {
        IPage<${ClassName}VO> result = ${ClassName?lower_case}Service.get${ClassName}Page(Condition.getPage(query),queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增${tableComment}")
    @PostMapping("/save")
    public Result save${ClassName}(@RequestBody @Valid ${ClassName}Entity formData) {
        boolean result = ${ClassName?lower_case}Service.save(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取${tableComment}表单数据")
    @GetMapping("/detail")
    public Result<${ClassName}Entity> get${ClassName}Form(
        @Parameter(name = "主键", required = true) @RequestParam Long id
    ) {
            ${ClassName}Entity formData = ${ClassName?lower_case}Service.getById(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改${tableComment}")
    @PutMapping(value = "/update")
    public Result update${ClassName}(
            @RequestBody ${ClassName}Entity entity
    ) {
        boolean result = ${ClassName?lower_case}Service.updateById(entity);
        return Result.judge(result);
    }

    @Operation(summary = "删除${tableComment}")
    @DeleteMapping("/remove")
    public Result delete${ClassName}s(
            @Parameter(name = "主键集合", required = true) @RequestParam String ids
    ) {
        boolean result = ${ClassName?lower_case}Service.removeBatchByIds(Func.toLongList(ids));
        return Result.judge(result);
    }
}
